package com.eipc;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Resources;
import android.os.Bundle;

import com.eipc.util.DBHelper;

/**
 * 刷新公共的activity
 * @author x_liaolijun
 *
 * 2010-10-5 下午12:36:58
 *  
 * RefreshCommonActivity
 *
 */
public class RefreshCommonActivity extends Activity {
	private PushFinishBroadcast  mPushReceiver;
	protected Resources mRe;
	protected DBHelper mDB;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		mRe = getResources();
		mDB = new DBHelper(this);
	}
	
	@Override
	protected void onDestroy() {
		super.onDestroy();
		if(mDB!=null) mDB.close();
	}
	
	protected void initView(){}
	
	protected void updateView(){}
	
	protected void startPush(){
		IntentFilter filter = new IntentFilter("action.push.finish");
		registerReceiver(mPushReceiver, filter);
	}
	
	protected void stopPush(){
		try {
			if(mPushReceiver!=null) unregisterReceiver(mPushReceiver);
		} catch (Exception e) {
		}
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		startPush();
	}
	
	@Override
	protected void onPause() {
		super.onPause();
		stopPush();
	}
	
	/*
	 * push结束广播
	 */
	class PushFinishBroadcast extends BroadcastReceiver{
		@Override
		public void onReceive(Context context, Intent intent) {
			updateView();
		}
	}
}
